<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <?php include 'head.php'; ?>
    </head>
    <body>
        <div id="main_wrapper">
            <!-- HEADER -->
            <div id="header">
                <?php include 'header.php'; ?>
            </div>

            <!-- ERROR BOX -->
            <?php if(isset ($error)) { ?>
            <div class="errorbox"><?php echo $error; ?></div>
            <?php } ?>

            <!-- CONTENT -->
            <div id="content">
                <!-- PROFILE BOX -->
                <div class ="profilebox">
                    <div class="upload_title" onclick="toggleVisibility(document.getElementById('profilefull')); toggleArrowBtn(document.getElementById('arr_profile'));">
                        <img src="<?php echo URL::base_url() . 'public/image/arrow_expand.gif' ?>" alt="" id="arr_profile"/>
                        <?php echo $user->username; ?>
                    </div>
                    <div id="profilefull">
                        <div class="profiledetail">
                            <div class="profileinfo">
                                <?php if ($auth_user->id != $view_user->id) { ?>
                                <?php if($show_follow) { ?>
                                <div class="follow"><a href="<?php echo URL::site("user/follow/" . $view_user->id); ?>">Follow this user</a></div>
                                <?php } else { ?>
                                <div class="follow"><a href="<?php echo URL::site("user/unfollow/" . $view_user->id); ?>">Unfollow this user</a></div>
                                <?php }
                                    }
                                ?>
                                <div class="profpic"><img src="<?php echo URL::base_url() . ($user_profic != null ? $user_profic : 'public/upload/default/profpic.png') ?>" alt="<?php echo $user->username ?>"/></div>
                                <div class="info"><?php echo $user->name ?></div>
                                <div class="info">
                                    <?php echo $user_age ?> years old
                                </div>
                                <div class="info">
                                    <?php
                                    $location = new ORM('location');
                                    $location = $location->find($user->location_id);
                                    ?>
                                    from <?php echo $location->location_name; ?>
                                </div>
                                <?php if($auth_user->role == "admin") : ?>
                                    <?php if($view_user->role == "user") : ?>
                                    <div class="follow"><a style="color: red" href="<?php echo URL::site("user/block/" . $view_user->id); ?>">Block this user</a></div>
                                    <?php endif;?>
                                    <?php if($view_user->role == "blocked") : ?>
                                    <div class="follow"><a style="color: red" href="<?php echo URL::site("user/unblock/" . $view_user->id); ?>">Unblock this user</a></div>
                                    <?php endif;?>
                                <?php endif;?>
                            </div>
                            <div class="follows">
                                <h2>Followers</h2>
                                <div class="imageWrapper">
                                    <?php foreach ($followers as $f) : ?>
                                    <div class="listimage">
                                        <a title="<?php echo $f['user']['name']; ?>" href="<?php echo URL::site("profile?uid=" . $f['user']['id']); ?>">
                                            <img class="gambar" src="<?php echo URL::base_url() . $f['photo']['link']; ?>" alt="ana" width="50px" height="50px" />
                                        </a>
                                    </div>
                                    <?php endforeach; ?>
                                </div>
                            </div>

                            <div class="follows">
                                <h2>Followings</h2>
                                <div class="imageWrapper">
                                    <?php foreach ($followings as $f) : ?>
                                    <div class="listimage">
                                        <a title="<?php echo $f['user']['name']; ?>" href="<?php echo URL::site("profile?uid=" . $f['user']['id']); ?>">
                                            <img class="gambar" src="<?php echo URL::base_url() . $f['photo']['link']; ?>" alt="ana" width="50px" height="50px" />
                                        </a>
                                    </div>
                                    <?php endforeach; ?>
                                </div>
                            </div>
                            <div class ="clear"></div>
                        </div>

                        <?php if($other_user === FALSE || $auth_user->role == "admin") : ?>
                        <div class="upload_title" onclick="toggleVisibility(document.getElementById('edit_profile_form')); toggleArrowBtn(document.getElementById('arr_edit_profile'));">
                            <img src="<?php echo URL::base_url() . 'public/image/arrow_collapse.gif' ?>" alt="" id="arr_edit_profile"/>
                            Edit Profile
                        </div>
                        <div class="upload" id="edit_profile_form" style="display: none">
                            <?php echo $form; ?>
                        </div>
                        <?php endif; ?>
                    </div>
                </div>


                <!-- PROFILECONTENT BOX -->
                <div class="profilecontent_box">
                    <ul class="profilecontent_tab">
                        <?php foreach ($profile_link as $key => $link) :?>
                        <li>
                            <a onclick="tabClick(this);" <?php if(isset($link['active'])) {?>class="active"<?php } if (isset($link['id'])){echo "id=\"" . $link['id'] . "\"";}?> i href="<?php echo URL::site($key); ?>"><?php echo $link['value']; ?></a>
                        </li>
                        <?php endforeach;?>
                    </ul>
                    <script type="text/javascript">
                        function tabClick(element) {
                            var dest = document.getElementById("ajax_profilecontent");

                            // Load element
                            loadElement(element.href, dest);

                            // Close all
                            closeNewsFeedIndex();
                            closeWallIndex();

                            // Deactive all link
                            getElementByClass("active", getElementByClass("profilecontent_tab")[0])[0].setAttribute("class", "");

                            // Activaed this link
                            element.setAttribute("class", "active");
                        }
                    </script>
                    <div class="clear"></div>
                    <div class="profilecontent" id="ajax_profilecontent">
                        <?php echo $content; ?>
                    </div>
                </div>
            </div>

            <!-- WRAPPER -->
            <div id="footer">
                <?php include 'footer.php'; ?>
            </div>
        </div>

        <div id="chat_client_wrapper" >
            <?php echo $chat_content; ?>
        </div>
    </body>
</html>




